// 注册页面钩子，方便其他注册插件
import "@/pagePlugin";
// core
import { createApp } from "vue"
import App from "@/App.vue"
import store from "@/store"
import router from "@/router"
import "@/router/permission"
// load
import { loadSvg } from "@/icons"
import { loadPlugins } from "@/plugins"
// css
import "uno.css"
import "normalize.css"
import "element-plus/dist/index.css"
import "element-plus/theme-chalk/dark/css-vars.css"
import "vxe-table/lib/style.css"
import "vxe-table-plugin-element/dist/style.css"
import "@/styles/index.scss"
import {checkAuths, checkPermission} from "@/utils/permission";
import {permission} from "@/directives/permission";
import {checkAuths as checkAuths2} from "@/directives/auths";
const app = createApp(App)

/** 加载插件 */
loadPlugins(app)
/** 加载全局 SVG */
loadSvg(app)

app.use(store).use(router)
app.config.globalProperties.checkPermission=checkPermission
app.config.globalProperties.checkAuths=checkAuths
app.directive("permission", permission)
app.directive("checkAuths", checkAuths2)
router.isReady()
  .then(async () => {
    // 路由准备好以后再调用一次
    const result = window.__pagePlugin__.plugins
      .filter(i => i.type === 'route')
    for (let pagePluginItem of result) {
      const handler = pagePluginItem.handler(window.__pagePlugin__, router);
      if (handler instanceof Promise) {
        await handler
      }
    }
  })
  .then(() => {
    app.mount("#app")
  })
